package com.zzy.controller;

import com.zzy.bridge.AbstractRegisterLoginComponent;
import com.zzy.bridge.RegisterLoginComponentFactory;
import com.zzy.bridge.RegisterLoginEnum;
import com.zzy.bridge.RegisterLoginFuncInterface;
import com.zzy.pojo.UserInfo;
import com.zzy.service.UserBridgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/bridge")
public class UserBridgeContorller {

    @Autowired
    private UserBridgeService userBridgeService;

    @PostMapping("/login")
    public String login(String account, String password) {
        AbstractRegisterLoginComponent registerLoginComponent = RegisterLoginComponentFactory.getInstance(RegisterLoginEnum.DEFAULT);
        return registerLoginComponent.login(account, password);
    }

    @PostMapping("register")
    public String register(@RequestBody UserInfo userInfo) {
        AbstractRegisterLoginComponent registerLoginComponent = RegisterLoginComponentFactory.getInstance(RegisterLoginEnum.DEFAULT);
        return registerLoginComponent.register(userInfo);
    }

    /**
     * https://gitee.com/oauth/authorize?client_id=8a852b580100838873e1e93776aba77da26f60893fd66da705f19377c11c3207&redirect_uri=http://localhost:8081/bridge/login3rd&response_type=code&state=GITEE
     * @param request
     * @return
     */
    @GetMapping("login3rd")
    public String login3rd(HttpServletRequest request) {
        AbstractRegisterLoginComponent registerLoginComponent = RegisterLoginComponentFactory.getInstance(RegisterLoginEnum.GITEE);
        return registerLoginComponent.login3rd(request);
    }
}
